<template>
  <div class="header">
    <div class="navbox">
      <!-- 弹出层导航栏 -->
      <div class="nav-box" :class="{ active: isNavVisible }">
        <div style="display: flex; justify-content: right">
          <img
            src="../assets/imagesfd/jixu.png"
            alt=""
            style="width: 20%; height: 20%"
            @click="hideNav()"
          />
        </div>
        <div class="navul">
          <ul>
            <router-link to="/" class="rout2">家</router-link>
          </ul>
          <ul>
            <router-link to="/aboutus" class="rout2">大约</router-link>
          </ul>
          <ul>
            <div
              style="display: flex; justify-content: space-between"
              @click="showservice()"
            >
              服务业
              <img
                src="../assets/images/tanchuang.png"
                alt=""
                style="width: 20px; height: 20px"
              />
            </div>
            <li v-if="serviceblock">
              <router-link to="/service" class="rout2">服务业</router-link>
            </li>
            <li v-if="serviceblock">
              <router-link to="/detail" class="rout2">详细</router-link>
            </li>
          </ul>
          <ul>
            <div style="display: flex; justify-content: space-between" @click="showblog()">
              博客<img
                src="../assets/images/tanchuang.png"
                alt=""
                style="width: 20px; height: 20px"
              />
            </div>
            <li v-if="blogblock"><router-link to="/blog" class="rout2">博客</router-link
              ></li>
            <li v-if="blogblock"><router-link to="/blogdetail" class="rout2">详细</router-link
              ></li>
          </ul>
          <ul>
            <router-link to="/callus" class="rout2">联系</router-link>
          </ul>
          <ul>
            <router-link to="/callus" class="rout2">字体排印学</router-link>
          </ul>
        </div>
      </div>
      <!-- nav顶部 -->
      <div class="navtop">
        <div class="navtopleft">
          <p>1-100-300-300</p>
          <p>email@domain.com</p>
        </div>
        <div>
          <img src="../assets/page/logo.png" alt="" />
        </div>
        <div class="navtopright">
          <div class="navimgbox">
            <img src="../assets/imagesfd/facebook.png" alt="" />
          </div>
          <div class="navimgbox">
            <img src="../assets/imagesfd/twitter.png" alt="" />
          </div>
          <div class="navimgbox">
            <img src="../assets/imagesfd/facebook.png" alt="" />
          </div>
          <div class="navimgbox">
            <img src="../assets/imagesfd/twitter.png" alt="" />
          </div>
          <div class="navimgboxlast">
            <span style="color: #919298">语言</span>
            <div class="navimgbox2">
              <img src="../assets/imagesfd/facebook.png" alt="" />
            </div>
          </div>
        </div>
      </div>
      <!-- nav顶部 -->
      <!-- nav第二层 -->
      <div class="twonav">
        <div class="tnleft">
          <img
            src="../assets/imagesfd/three.png"
            alt=""
            class="tnleftimg"
            @click="showNav"
          />
        </div>
        <div class="tncenter">
          <ul>
            <a href=""> <router-link to="/" class="rout">家</router-link></a>
          </ul>
          <ul>
            <a href=""
              ><router-link to="/aboutus" class="rout">大约</router-link></a
            >
          </ul>
          <ul @click="showlala()">
            服务业
            <img
              src="../assets/imagesfd/sanjiao.png"
              alt=""
              style="width: 10px; height: 10px"
            />
            <div class="lala1" v-if="showbox">
              <li>
                <router-link to="service" class="rout">服务业</router-link>
              </li>
              <li><router-link to="detail" class="rout">详细</router-link></li>
            </div>
          </ul>
          <ul @click="showlala2()">
            博客
            <img
              src="../assets/imagesfd/sanjiao.png"
              alt=""
              style="width: 10px; height: 10px"
            />
            <div class="lala2" v-show="showbox2">
              <li>
                <router-link to="/blog" class="rout">博客</router-link>
              </li>
              <li>
                <router-link to="/blogdetail" class="rout">详细</router-link>
              </li>
            </div>
          </ul>
          <ul>
            <a href=""
              ><router-link to="/callus" class="rout">联系</router-link></a
            >
          </ul>
          <ul>
            <a href=""
              ><router-link to="/design" class="rout"
                >字体排印学</router-link
              ></a
            >
          </ul>
        </div>
        <div class="tnright">
          <img src="../assets/imagesfd/sousuo.png" alt="" class="tnrightimg" />
        </div>
      </div>
      <!-- nav第二层 -->
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      isNavVisible: false,
      showbox: false,
      showbox2: false,
      serviceblock: false,
      blogblock:false
    };
  },
  methods: {
    showservice() {
      this.serviceblock = !this.serviceblock;
    },
    showblog() {
      this.blogblock = !this.blogblock;
    },
    showlala() {
      this.showbox = !this.showbox;
    },
    showlala2() {
      this.showbox2 = !this.showbox2;
    },
    showNav() {
      this.isNavVisible = true;
    },
    hideNav() {
      this.isNavVisible = false;
    },
  },
};
</script>

<style lang="scss">
.nav-box > ul > li > router-link {
  text-decoration: none;
  color: white;
}
.nav-box {
  z-index: 999;
  position: fixed;
  left: -30%; /* 初始位置在屏幕左侧之外 */
  top: 0;
  width: 15%;
  height: 100%;
  background-color: #28272d;
  transition: left 0.3s ease; /* 过渡效果 */
}

.nav-box.active {
  left: 0; /* 移入时显示在屏幕内 */
}
.navul > ul {
  list-style: none;
  color: white;
  padding: 20px;
  // display: flex;
  // justify-content: space-between;
  border-bottom: 1px solid #232228;
}
.navul > ul > li {
  padding: 20px 0;
}
.navul > ul:hover {
  background-color: #198adf;
}
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;

  .navbox {
    margin-top: 30px;
    // nav顶部
    .navtop {
      width: 70%;
      margin: auto;
      display: flex;
      justify-content: space-between;
      .navtopleft {
        display: flex;
        font-size: 10px;
      }
      .navtopleft > p {
        margin: 10px;
      }
      .navtopright {
        display: flex;
        .navimgbox {
          width: 20px;
          height: 20px;
          margin: 5px;
          background-color: #f7f7f7;
          border-radius: 50%;
        }
        .navimgbox > img {
          width: 70%;
          height: 70%;
          margin: auto;
          height: auto;
        }
        .navimgboxlast {
          display: flex;
          margin: 5px;
          width: 100px;
          height: 20px;
          border-top-left-radius: 20px;
          border-bottom-left-radius: 20px;
          background-color: #f7f7f7;
        }
        .navimgbox2 {
          margin-left: 40px;
          width: 20px;
          height: 20px;
          background-color: white;
          border-radius: 50%;
        }
        .navimgbox2 > img {
          width: 70%;
          height: 70%;
          margin: auto;
          height: auto;
        }
      }
    }
    // nav顶部
    .rout {
      color: black;
      text-decoration: none;
    }
    .rout2{
      color: white;
      text-decoration: none;
    }
    // nav第二层
    .twonav {
      background-color: #f8f8f8;
      display: flex;
      justify-content: space-between;
      width: 70%;
      margin: auto;
      height: 50px;
      line-height: 50px;
      padding: 0 20px;
      box-sizing: border-box;

      .tnleftimg {
        width: 10px;
        height: 10px;
      }

      .tncenter {
        width: 50%;
        display: flex;
        justify-content: space-between;
      }
      .tncenter > ul > a {
        text-decoration: none;
        color: black;
      }
      .tncenter > ul {
        position: relative;
        cursor: pointer;
      }

      .lala1 {
        list-style: none;
        display: block;
        z-index: 99;
        position: absolute;
      }
      .lala2 {
        list-style: none;
        display: block;
        z-index: 99;
        position: absolute;
      }
      .tnrightimg {
        padding-top: 5px;
        box-sizing: border-box;
        width: 20px;
        height: 20px;
        position: relative;
      }
    }
    // nav第二层
  }
}

// 响应1024px
@media (max-width: 1024px) {
  .nav-box {
    width: 30%;
    left: -30%;
  }
  .navbox {
    .navtop {
      display: block;
      text-align: center;
      .navtopleft {
        display: block;
      }
      .navtopright {
        display: none;
      }
    }

    .twonav {
      .tncenter {
        display: none;
      }
    }
  }
}

// 响应370px
@media (max-width: 370px) {
  .nav-box {
    width: 50%;
    left: -50%;
  }
  .navbox {
    .navtop {
      display: block;
      text-align: center;
      .navtopleft {
        display: block;
      }
      .navtopright {
        display: none;
      }
    }
  }
}
</style>